package com.ymatou.iapi.csim.testcase;

import net.sf.json.JSONObject;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.GetCountBean;
import com.ymatou.iapi.csim.parameter.SendMessageBean;
import com.ymatou.iapi.csim.service.GetCountCall;
import com.ymatou.iapi.csim.service.SendMessageCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_cssession;
import com.ymttest.database.model.ymt_onlinecs;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_queuesessionWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
/**
*获取会话队列数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetCount{
	private static GetCountBean bean;
	private static GetCountCall call;
	private CsimCallService service=new CsimCallService();
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private Integer userId=Integer.parseInt(EnvSetup.getData("userId_IM").toString());
	private Integer sellerId1=Integer.parseInt(EnvSetup.getData("autotest_seller1").toString());
	private static ymt_cssessionWapper csSessionWapper=new ymt_cssessionWapper();
	private static ymt_onlinecsWapper onlinecsWapper=new ymt_onlinecsWapper();
	private static ymt_queuesessionWapper queuesessionWapper=new ymt_queuesessionWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取会话队列数");
	}

	@Before
	public void caseUp() {
		bean=new GetCountBean();
		call=new GetCountCall();
		csSessionWapper.deleteByUserId(null);
		onlinecsWapper.deleteBy(null);
		queuesessionWapper.deleteAll();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCount_1() {
		Logger.start(true,"获取会话队列数-用户类型：买家");
		try {
			SendMessageBean sendMessageBean=service.setSendMessageBean();
			sendMessageBean.setUserId(userId);
			SendMessageCall sendMessageCall=service.setSendMessageCall(sendMessageBean);
			bean.setType(0);//用户类型
			bean.setCallType(0);
			call.setData(bean);
			call.callService();			
			//验证
			int count=queuesessionWapper.selectBy_Count(MapUtil.hashMap("IsLock",0,"UserType",bean.getType(),"CallType",bean.getCallType()));
			Logger.verifyEquals( String.valueOf(count),DataUtil.Json.parseJsonObj(call.getString("Result")).get("Count").toString(), "验证Count");
			Logger.verifyEquals("200",call.getString("Status"), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCount_2() {
		Logger.start(true,"获取会话队列数-用户类型：买手");
		try {
			SendMessageBean sendMessageBean=service.setSendMessageBean();
			sendMessageBean.setUserId(sellerId1);
			SendMessageCall sendMessageCall=service.setSendMessageCall(sendMessageBean);
			bean.setType(1);//用户类型
			bean.setCallType(0);
			call.setData(bean);
			call.callService();			
			//验证
			int count=queuesessionWapper.selectBy_Count(MapUtil.hashMap("IsLock",0,"UserType",bean.getType(),"CallType",bean.getCallType()));
			Logger.verifyEquals(DataUtil.Json.parseJsonObj(call.getString("Result")).get("Count").toString(), String.valueOf(count), "验证Count");
			Logger.verifyEquals("200",call.getString("Status"), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCount_3() {
		Logger.start(true,"获取会话队列数-存在会话中，不显示会话队列中");
		try {
			//csIdA上线
			ymt_onlinecs onlinecs=service.getOnlineCS(csId);
			//csIdA 主动会话
			ymt_cssession csSession=service.getOpenSession(csId,userId);
			
			SendMessageBean sendMessageBean=service.setSendMessageBean();
			sendMessageBean.setUserId(userId);
			SendMessageCall sendMessageCall=service.setSendMessageCall(sendMessageBean);
			bean.setType(0);//用户类型
			bean.setCallType(0);
			call.setData(bean);
			call.callService();			
			//验证
			int count=queuesessionWapper.selectBy_Count(MapUtil.hashMap("IsLock",0,"UserType",bean.getType(),"CallType",bean.getCallType()));
			Logger.verifyEquals(0,DataUtil.Json.parseJsonObj(call.getString("Result")).get("Count"), "验证Count");
			Logger.verifyEquals("200",call.getString("Status"), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}